// 写文件
var fs = require('fs');
fs.open('./textwrite.txt', 'w', function(err, fd) {
    if (err) {
        throw err;
    }

    console.log('打开文件');

    var buffer = new Buffer('shiyanlou'); // 将要写入的文字
    fs.write(fd, buffer, 0, 6, 0, function(err, written, buffer) {
        if (err) {
            throw err;
        }

        console.log('写入成功');
        var btyteLen = buffer.byteLength;
        console.log(btyteLen, buffer.slice(0, btyteLen).toString());
        fs.close(fd);
    });
});